	{layout name="main"/}
<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-title">
                    <a href="{:url('admin/Mall/add')}" class="btn btn-primary btn-sm"><i class="fa fa-edit"></i> 新增 商城/旗舰店 </a>
                </div>

            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-title">
                    <h5>商城/旗舰店列表</h5>

                </div>

                <div class="ibox-content">


                    <div class="row m-b-sm m-t-sm">


                    </div>

                    <div class="row m-b-sm m-t-sm">
                        <div class="col-sm-5">
                            <a href="{:url('admin/Mall/showlist',['is_rec'=>'all'])}" class="btn-sm btn {if condition="$is_rec eq 'all'"} btn-info {else} btn-default {/if}">全部</a>
                            <a href="{:url('admin/Mall/showlist',['is_rec'=>'a'])}" class="btn-sm btn {if condition="$is_rec eq 'a'"} btn-info {else} btn-default {/if}">已推荐</a>
                            <a href="{:url('admin/Mall/showlist',['is_rec'=>'b'])}" class="btn-sm btn {if condition="$is_rec eq 'b'"} btn-info {else} btn-default {/if}">未推荐</a>
                        </div>
                    </div>
                    <div class="project-list">
                        <table class="footable table table-stripped toggle-arrow-tiny">
                            <thead>
                            <tr>

                                <th  style="width: 60%;">名称</th>
                                <th  style="width: 5%;">排序</th>
                                <th  style="width: 10%;">访问量</th>
                                <th  style="width:25%;">操作</th>

                                <th data-hide="all"></th>

                            </tr>
                            </thead>
                            <!--                            <tbody><tr class="no-records-found"><td colspan="8">没有找到匹配的记录</td></tr></tbody>-->
							{:table_empty_list($malltres,'暂无数据!',7)}
							{volist name="$malltres" id="vo"}
                            <tr>
                                <td>
                                    <a href="###">
                                        <img src="{$vo.mall_img}" style="width: 22px; border-radius:20%; position: relative;top:-2px;vertical-align: middle;" />
                                        <span>{$vo.mall_name}</span>
                                     </a>
                                    - {$vo.sub_name}
                                </td>
                                <td class="center ">
                                   {$vo.sort_order}
                                </td>
                                <td class="center ">
                                   {$vo.click}
                                </td>
                                <td class="center">
                                	{if condition="$vo.is_rec" eq 0 }
                    				<a href="javascript:isrec2('{$vo.mall_id}');" class="btn btn-danger btn-xs" ><i class="fa fa-paste"></i>取消推荐</a>
                    				{else/}
                    				<a href="javascript:is_rec('{$vo.mall_id}');" class="btn btn-primary btn-xs" ><i class="fa fa-paste"></i>我要推荐</a>
                    				{/if}
                    				<a href="{:url('admin/Mall/edit',['mall_id'=>$vo.mall_id])}" class="btn btn-danger btn-xs" ><i class="fa fa-paste"></i> 编辑</a>
                    				
									<a href="javascript:del('{$vo.mall_id}');" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i> 删除</a>
                                </td>

                                <td>
                                		{volist name="$vo.class" id="vv"}
                                        <div>
                                            {if $vv.mall_img} <img src="{$vv.mall_img}" style="width: 22px; border-radius:20%; position: relative;top:-2px;vertical-align: middle;" />{/if}
                                            <a href="#">{$vv.mall_name}</a>
                                            &nbsp;&nbsp;
                                            [ {$vv.click}次访问 ]
                                           &nbsp;&nbsp;
                                            {if condition="$vv.is_rec" eq 0 }
                                            [ <a href="javascript://" onclick="isrec('{$vv.mall_id}','notj',this);">取消推荐</a>
                                            {else/}
                                            [ <a href="javascript://" onclick="isrec('{$vv.mall_id}','tj',this); " >推荐</a>
                                            {/if}
                                            <a href="{:url('admin/Mall/editlist',['mall_id'=>$vv.mall_id])}">编辑</a>
                                            		
                                           <a href="javascript:del('{$vv.mall_id}');">删除</a> ]
                                        </div>
										{/volist}
                                </td>
                            </tr>
							{/volist}
                        </table>



                        <div class="row">
                            <div class="col-sm-6">
                                <div class="dataTables_info" id="DataTables_Table_0_info" role="alert" aria-live="polite" aria-relevant="all">
                                    每页显示 {:getPageSize()} 项，共{$malltres->toArray()['total']} 项</div></div>
                            <div class="col-sm-6">
                                <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
                                    {$malltres->render()}

                                </div>

                            </div>
                        </div>


                    </div>
                </div>

            </div>
        </div>
    </div>

</div>
<style>
    .project-list div{ line-height: 30px;}
</style>
<script>

    $(document).ready(function () {
        $(".footable").footable();
    });
    $(".input-daterange").datepicker({keyboardNavigation: !1, forceParse: !1, autoclose: !0});

    function del(mall_id) {
        swal({
            title: "您确定要删除这条信息吗",
            text: "删除后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "删除",
            closeOnConfirm: false,
            cancelButtonText: "取消",

        }, function (isConfirm) {
            if(!isConfirm){return;}
            post({
                url: "{:url('/admin/Mall/del')}",
                data: {mall_id: mall_id},
                success: function(res) {
                    swal({
                        title: 'success',
                        text: res.message,
                        type: "success"
                    }, function() {
                        reload();
                    });
                },
                error: function(error) {
                    swal("错误", JSON.parse(error.responseText).message, "error");
                }
            });


        });
    }
    //我要推荐方法
    function is_rec(mall_id){
        swal({
            title: "您是否推荐",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的",
            closeOnConfirm: false,
            cancelButtonText: "取消",

        }, function (isConfirm) {
            post({
                url: "{:url('/admin/Mall/is_rec')}",
                data: {mall_id: mall_id},
                success: function(res) {
                    swal({
                        title: 'success',
                        text: res.message,
                        type: "success"
                    }, function() {
                        reload();
                    });
                },
                error: function(error) {
                    swal("错误", JSON.parse(error.responseText).message, "error");
                }
            });


        });
    }

//    //子分类推荐
    function isrec(mall_id,type,obj){
        post({
            url: "{:url('Mall/isrec')}", //传送地址
            type: "post",
            data: {mall_id: mall_id}, //子分类推荐DI也传送到后台接受
            success:function(res) {
//////                接受过来是一个对象
                if(res.status == 'success'){
//                    当他等于不推荐的时候就执行下面那个取消推荐方法
                    if(type=="notj"){
                        $(obj).html("推荐");
//                        追加到后面那个
                        $(obj).attr("onclick","isrec('"+mall_id+"','tj',this)");
                    }else{
                        $(obj).html("取消推荐");
                        $(obj).attr("onclick","isrec('"+mall_id+"','notj',this)");
                    }
                }
            },
            error: function (error) {
                swal("错误", JSON.parse(error.responseText).message, "error");
            }
//
        });
    }




    //取消推荐
    function isrec2(mall_id){
        swal({
            title: "您是否取消推荐",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "是的",
            closeOnConfirm: false,
            cancelButtonText: "取消",

        }, function (isConfirm) {
            post({
                url: "{:url('/admin/Mall/is_rec')}",
                data: {mall_id: mall_id},
                success: function(res) {
                    swal({
                        title: 'success',
                        text: res.message,
                        type: "success"
                    }, function() {
                        reload();
                    });
                },
                error: function(error) {
                    swal("错误", JSON.parse(error.responseText).message, "error");
                }
            });


        });
    }

    //排序修改
    function updateSortorder(mall_id,obj){


        var sort_order=$(obj).val();

        post({
            url: "{:url('/admin/Mall/updateSortorder')}",
            data: {mall_id: mall_id,sort_order: sort_order},
            success: function (res) {

            },
            error: function (error){

                swal("错误", JSON.parse(error.responseText).message, "error");
            }

        });
    }
</script>





























